package com.service.impl;

import com.dao.ProductDao;
import com.dao.impl.ProductDaoImpl;
import com.entity.PageBean;
import com.entity.Product;
import com.service.ProductService;

import java.sql.SQLException;
import java.util.List;

/**
 * @ProjectName: shop
 * @Author: Jsx
 * @Time: 2020/8/30 21:30
 * @Description:
 */
public class ProductServiceImpl implements ProductService {
    @Override
    public PageBean<Product> findAll(String tid, String currentPage, String pageSize) throws SQLException {

        //1.请求处理参数
        int cp = 1;
        if (currentPage != null) {
            cp=Integer.parseInt(currentPage);
        }

        int ps = 8;
        if (pageSize != null) {
            ps=Integer.parseInt(pageSize);
        }
        ProductDao productDao = new ProductDaoImpl();
        List<Product> products = productDao.queryProductById(tid, cp, ps);

        Long totalCount = productDao.queryCountByTid(tid);

        //int currentPage, int pageSize, long totalCount, List<T> data
        PageBean<Product> pageBean = new PageBean<>(cp,ps,totalCount,products);
        return pageBean;
    }
}
